package com.ydd.service.Impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.ydd.dto.YddAdvimgPageDTO;
import com.ydd.entity.YddAdvimg;
import com.ydd.mapper.YddAdvimgMapper;
import com.ydd.mapper.YddAdvposMapper;
import com.ydd.service.AdvimgService;
import com.ydd.vo.DataListVO;
import com.ydd.vo.YddAdvimgListVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class AdvimgServiceImp implements AdvimgService {
    @Autowired
    private YddAdvimgMapper yddAdvimgMapper;
    @Autowired
    private YddAdvposMapper yddAdvposMapper;

    /**
     * 广告图详情
     *
     * @return
     */
    @Override
    public YddAdvimg findAll(String id) {
        return yddAdvimgMapper.findAll(id);
    }

    /**
     * 广告图分页查询
     *
     * @param yddAdvimgPageDTO
     * @return
     */
    @Override
    public DataListVO findpage(YddAdvimgPageDTO yddAdvimgPageDTO) {
        PageHelper.startPage(yddAdvimgPageDTO.getPage(),yddAdvimgPageDTO.getLimit());
        List<YddAdvimgListVO> yddAdvimgListVOS=yddAdvimgMapper.findpage();
        for (YddAdvimgListVO list : yddAdvimgListVOS) {
            list.setAdvposname(yddAdvposMapper.selectAdvposname(list.getAdvimgpos()));
        }
        Page<YddAdvimgListVO> pageInfo=(Page<YddAdvimgListVO>) yddAdvimgListVOS;
        Integer count=(int) pageInfo.getTotal();
        return new DataListVO(
                count,
                pageInfo.getPages(),
                yddAdvimgPageDTO.getLimit(),
                yddAdvimgPageDTO.getPage(),
                pageInfo.getResult()
        );
    }
}
